{$i-,s-,g+,r-}
{$ifndef modif}{$i modif.inc}{$endif}
Program MaskFiltration;
uses {$ifdef Windows}
     WinCrtx,WinDos,
     {$else}
      {$ifdef crtx}crtx,{$else}crt,{$endif}dos,
     {$endif}
     pictures,ToolsB;

var vystup,a:string;
    fbr,obr:Picture;
    i,j:integer;
    MaxP,p:Byte;
    MarkedTime:Longint;
    n:real;
    PassLProc:PercentLineProc;


Function GetInterval:Longint; assembler;
asm
	MOV	AH,0
	INT	1Ah
        MOV	AX,DX
	MOV	DX,CX
end;


Label 1,10,20,Finish;


const Title:array[0..16]of char='Mask Filtration'#0;
begin
{$ifdef Windows}
ScreenSize.X:=62;
ScreenSize.Y:=10;
WindMax:=ScreenSize;
Move(Title,WindowTitle,Sizeof(Title));
{$endif}
PassLProc.init;
obr.init;
fbr.init;
{$ifndef  Windows}
  DirectVideo:=False;
  nosound;
{$endif}
 writeln(#10#13'<<< MASK >>> Mask picture filtration (c)1995-2009 F&TSoft');
 vystup:='';
 n:=1;
 if Paramcount=0 then
	begin
1:	write('Enter name of input picture:');readln(a);
	if a='' then goto 1;
	assignpicture(obr,a);
	write('Enter name of output picture:');readln(a);
	vystup:=a;
10:     write('Enter size of mask:');readln(a);
	val(a,n,j);
	if (j<>0)or(n<=0) then
		     begin
		     writeln('Error:Incorrect number ',a);
		     goto 10;
		     end;
	end;

 for i:=1 to paramcount do
	begin
	a:=paramStr(i);
	if((a[2]='?')or(a[1]='?'))or((UpCases(a)='/HELP')or(UpCases(a)='-HELP')) then
		begin
		writeln(#10#13'MASK file_in file_out [size] '#10#13+
			      'Supported file formats are BMP,OKO,PCX,RAS'#10#13);
		{$ifdef Windows}InactiveWinCrt;{$endif}
		exit;
		end;

	if a[1] in ['-','+','0'..'9'] then
		      begin
		      val(a,n,j);
		      if j<>0 then begin
				   writeln('Error:Incorrect number ',a);
				   {$ifdef Windows}InactiveWinCrt;{$endif}
				   exit;
				   end;
		      end
		else
		begin
		if obr.filename=nil then assignpicture(obr,a);
		vystup:=a;
		end;

	end;

 if n<0.9 then
	begin
	writeln('Error:Incorrect size');
	{$ifdef Windows}InactiveWinCrt;{$endif}
	exit;
	end;

 if obr.filename=nil then
	begin
	writeln('Error:Unknown filename');
	{$ifdef Windows}
	while PeepError<>0 do writeln('Error: ',GetErrorString(ReadError));
	InactiveWinCrt;
	exit;
	{$else}
	goto Finish;
	{$endif}
	end;
 write(#13'Loading ');ClrEol;
 loadpicture(obr,'',@PassLProc);{} {  loadpicture(fbr);{}
 if obr.data=nil then
	begin
	writeln(#10#13'Cannot find input picture:''',obr.filename^,'''');
	{$ifdef Windows}
	while PeepError<>0 do writeln('Error: ',GetErrorString(ReadError));
	InactiveWinCrt;
	exit;
	{$else}
	goto Finish;
	{$endif}
	end;

 markedTime:=GetInterval;
 write(#13'Filtering ');ClrEol;
 Mask(Obr,fbr,round(n),@PassLProc);


 obr.Done;
 write(#13'Saving  ');ClrEol;
 if not(savepicture(fbr,vystup,@PassLProc)) then
	begin
	writeln(#10#13'Cannot save Output picture:''',fbr.filename^,'''');
{$ifdef Windows}InactiveWinCrt;{$endif}
	exit;
	end;
 writeln(#13' OK     ');ClrEol;

Finish:
 while PeepError<>0 do writeln('Error: ',GetErrorString(ReadError));
 fbr.Done;
end.
